package com.example.cloudsentinel.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.example.cloudsentinel.common.CommonException;
import com.example.cloudsentinel.common.CommonFlowRules;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class SentinelAnnotationController {


    @GetMapping("/testAspect/{id}")
    @SentinelResource(value = CommonFlowRules.ANNOTATION_RESOURCE_NAME,
            fallback = "fallback", fallbackClass = CommonException.class,
            blockHandler = "handleException", blockHandlerClass = CommonException.class
    )
    public String testAspect(@PathVariable("id") Integer id) {
        if (Integer.compare(id, Integer.parseInt("0")) == -1) {
            throw new IllegalArgumentException("参数异常");
        }

        log.info("处理业务信息");
        return "测试注解方式限流正常";
    }


}

